home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / lang / sofa.lha / sofa / smalleiffel / lib_se / tmp_feature.e < prev    next >
Text File  |  2000-03-25  |  10KB  |  310 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. expanded class TMP_FEATURE
  17.    --
  18.    -- Temporary object used during syntax analysis.
  19.    -- At the end, the good effective E_FEATURE is choose.
  20.    --
  21.  
  22. inherit GLOBALS;
  23.  
  24. feature {EIFFEL_PARSER}
  25.  
  26.    arguments: FORMAL_ARG_LIST;
  27.  
  28.    type: TYPE;
  29.  
  30.    header_comment: COMMENT;
  31.  
  32.    obsolete_mark: MANIFEST_STRING;
  33.  
  34.    require_assertion: E_REQUIRE;
  35.  
  36.    local_vars: LOCAL_VAR_LIST;
  37.  
  38.    routine_body: COMPOUND;
  39.  
  40.    initialize is
  41.       do
  42.          names.clear;
  43.          arguments := Void;
  44.          type := Void;
  45.          header_comment := Void;
  46.          obsolete_mark := Void;
  47.          require_assertion := Void;
  48.          local_vars := Void;
  49.          routine_body := Void;
  50.       end;
  51.  
  52.    add_synonym(a_name: FEATURE_NAME) is
  53.       require
  54.          a_name /= Void
  55.       do
  56.          if a_name.to_string = as_void then
  57.             eh.add_position(a_name.start_position);
  58.             fatal_error("Feature `Void' cannot be redefined (builtin).");
  59.          end;
  60.          names.add_last(a_name);
  61.       end;
  62.  
  63.    set_arguments(args: like arguments) is
  64.       require
  65.          args /= Void
  66.       do
  67.          arguments:= args;
  68.       end;
  69.  
  70.    set_type(t: like type) is
  71.       require
  72.          t /= Void
  73.       do
  74.          type := t;
  75.       ensure
  76.          type = t;
  77.       end;
  78.  
  79.    set_header_comment(hc: like header_comment) is
  80.       do
  81.          header_comment := hc;
  82.       end;
  83.  
  84.    set_obsolete_mark(om: like obsolete_mark) is
  85.       do
  86.          obsolete_mark := om;
  87.       end;
  88.  
  89.    set_local_vars(lv: like local_vars) is
  90.       do
  91.          local_vars := lv;
  92.       end;
  93.  
  94.    set_require(sp: POSITION; hc: COMMENT; al: ARRAY[ASSERTION]) is
  95.       do
  96.          if hc /= Void or else al /= Void then
  97.             !!require_assertion.make(sp,hc,al);
  98.          end;
  99.       end;
  100.  
  101.    set_require_else(sp: POSITION; hc: COMMENT; al: ARRAY[ASSERTION]) is
  102.       do
  103.          if hc /= Void or else al /= Void then
  104.             !!require_assertion.make(sp,hc,al);
  105.             require_assertion.set_require_else;
  106.          end;
  107.       end;
  108.  
  109.    set_routine_body(rb: like routine_body) is
  110.       do
  111.          routine_body := rb;
  112.       end;
  113.  
  114.    to_writable_attribute: WRITABLE_ATTRIBUTE is
  115.       do
  116.          if type = Void then
  117.             error(names.first.start_position,
  118.                   "Bad feature definition.");
  119.          elseif arguments /= Void then
  120.             eiffel_parser.ecp("Attribute must not have formal arguments.");
  121.          end;
  122.          !!Result.make(n,type);
  123.       end;
  124.  
  125.    to_cst_att_boolean(value: BOOLEAN_CONSTANT): CST_ATT_BOOLEAN is
  126.       do
  127.          to_cst_att_check_result_type;
  128.          if type.is_boolean then
  129.             !!Result.make(n,type,value);
  130.          else
  131.             error(type.start_position,
  132.                   "The type of this constant feature should be BOOLEAN.");
  133.          end;
  134.       end;
  135.  
  136.    to_cst_att_bit(value: BIT_CONSTANT): CST_ATT_BIT is
  137.       do
  138.          to_cst_att_check_result_type;
  139.          if type.is_bit then
  140.             !!Result.make(n,type,value);
  141.          else
  142.             error(type.start_position,
  143.                   "The type of this constant feature should be BIT.");
  144.          end;
  145.       end;
  146.  
  147.    to_cst_att_character(value: CHARACTER_CONSTANT): CST_ATT_CHARACTER is
  148.       do
  149.          to_cst_att_check_result_type;
  150.          if type.is_character then
  151.             !!Result.make(n,type,value);
  152.          else
  153.             error(type.start_position,
  154.                   "The type of this constant feature should be CHARACTER.");
  155.          end;
  156.       end;
  157.  
  158.    to_cst_att_integer(value: INTEGER_CONSTANT): CST_ATT is
  159.       do
  160.          to_cst_att_check_result_type;
  161.          if type.is_integer then
  162.             !CST_ATT_INTEGER!Result.make(n,type,value);
  163.          elseif type.is_real then
  164.             !CST_ATT_REAL!Result.make(n,type,value.to_real_constant);
  165.          elseif type.is_double then
  166.             !CST_ATT_DOUBLE!Result.make(n,type,value.to_real_constant);
  167.          else
  168.             error(type.start_position,
  169.                   "The type of this constant feature should be INTEGER %
  170.                   %REAL or DOUBLE.");
  171.          end;
  172.       end;
  173.  
  174.    to_cst_att_real(value: REAL_CONSTANT): CST_ATT is
  175.       do
  176.          to_cst_att_check_result_type;
  177.          if type.is_real then
  178.             !CST_ATT_REAL!Result.make(n,type,value);
  179.          elseif type.is_double then
  180.             !CST_ATT_DOUBLE!Result.make(n,type,value);
  181.          else
  182.             eh.add_position(type.start_position);
  183.             fatal_error("The type of this constant feature %
  184.                         %should be REAL or DOUBLE.");
  185.          end;
  186.       end;
  187.  
  188.    to_cst_att_string(value: MANIFEST_STRING): CST_ATT_STRING is
  189.       do
  190.          to_cst_att_check_result_type;
  191.          if type.is_string then
  192.             !!Result.make(n,type,value);
  193.          else
  194.             error(type.start_position,
  195.                   "The type of this constant feature should be STRING.");
  196.          end;
  197.       end;
  198.  
  199.    to_deferred_routine: DEFERRED_ROUTINE is
  200.       do
  201.          if type = Void then
  202.             !DEFERRED_PROCEDURE!Result.make(n, arguments,
  203.                                             obsolete_mark,
  204.                                             header_comment,
  205.                                             require_assertion);
  206.          else
  207.             !DEFERRED_FUNCTION!Result.make(n, arguments, type,
  208.                                            obsolete_mark,
  209.                                            header_comment,
  210.                                            require_assertion);
  211.          end;
  212.       end;
  213.  
  214.    to_external_routine(native: NATIVE; alias_tag: STRING): EXTERNAL_ROUTINE is
  215.       do
  216.          if type = Void then
  217.             !EXTERNAL_PROCEDURE!Result.make(n, arguments,
  218.                                             obsolete_mark,
  219.                                             header_comment,
  220.                                             require_assertion,
  221.                                             native,alias_tag);
  222.          else
  223.             !EXTERNAL_FUNCTION!Result.make(n, arguments, type,
  224.                                            obsolete_mark,
  225.                                            header_comment,
  226.                                            require_assertion,
  227.                                            native,alias_tag);
  228.          end;
  229.       end;
  230.  
  231.    to_once_routine: ONCE_ROUTINE is
  232.       do
  233.          if type = Void then
  234.             !ONCE_PROCEDURE!Result.make(n, arguments,
  235.                                         obsolete_mark,
  236.                                         header_comment,
  237.                                         require_assertion,
  238.                                         local_vars,
  239.                                         routine_body);
  240.          else
  241.             !ONCE_FUNCTION!Result.make(n, arguments, type,
  242.                                        obsolete_mark,
  243.                                        header_comment,
  244.                                        require_assertion,
  245.                                        local_vars,
  246.                                        routine_body);
  247.          end;
  248.       end;
  249.  
  250.    to_procedure_or_function: EFFECTIVE_ROUTINE is
  251.       do
  252.          if type = Void then
  253.             !PROCEDURE!Result.make(n, arguments,
  254.                                    obsolete_mark,
  255.                                    header_comment,
  256.                                    require_assertion,
  257.                                    local_vars,
  258.                                    routine_body);
  259.          else
  260.             !FUNCTION!Result.make(n, arguments, type,
  261.                                   obsolete_mark,
  262.                                   header_comment,
  263.                                   require_assertion,
  264.                                   local_vars,
  265.                                   routine_body);
  266.          end;
  267.       end;
  268.  
  269.    to_cst_att_unique: CST_ATT_UNIQUE is
  270.       do
  271.          if type = Void then
  272.             eh.add_position(names.first.start_position);
  273.             fatal_error(em01);
  274.          elseif type.is_integer then
  275.             !!Result.make(n,type);
  276.          else
  277.             eh.add_position(type.start_position);
  278.             fatal_error(em01);
  279.          end;
  280.       end;
  281.  
  282. feature {NONE}
  283.  
  284.    names: FIXED_ARRAY[FEATURE_NAME] is
  285.       once
  286.          !!Result.make(8);
  287.       end;
  288.  
  289.    to_cst_att_check_result_type is
  290.       do
  291.          if type = Void then
  292.             eh.add_position(names.first.start_position);
  293.             fatal_error("Bad constant declaration (no result type).");
  294.          elseif not type.is_run_type then
  295.             eh.add_position(type.start_position);
  296.             fatal_error("Must not use such a type for constant.");
  297.          end;
  298.       end;
  299.  
  300.    n: FEATURE_NAME_LIST is
  301.       require
  302.          not names.is_empty;
  303.       do
  304.          !!Result.make_n(names);
  305.       end;
  306.  
  307.    em01: STRING is "Unique feature must have INTEGER type.";
  308.  
  309. end -- TMP_FEATURE
  310.